# 和估值函数有关系的内容


# 棋子对应的分数
SCORE_LIST = {
    'P': 100,
    'B': 325,
    'N': 300,
    'R': 500,
    'Q': 900,
    'p': -100,
    'b': -325,
    'n': -300,
    'r': -500,
    'q': -900,
    'K': 0,
    'k': 0,
    '.': 0,
    ' ': 0,
}


# 棋子类型的枚举
class Pieces:
    WHITE_PAWN = "P"
    WHITE_ROOK = "R"
    WHITE_BISHOP = "B"
    WHITE_KNIGHT = "N"
    WHITE_KING = "K"
    WHITE_QUEEN = "Q"
    BLACK_PAWN = "p"
    BLACK_ROOK = "r"
    BLACK_BISHOP = "b"
    BLACK_KNIGHT = "n"
    BLACK_KING = "k"
    BLACK_QUEEN = "q"
    EMPTY = "."


# 棋盘位置 为了和chess库做匹配
class Board:
    # 棋盘位置对应的顺序，chess不是按下标排序的，而是白棋在下面
    BOARD_PLACE = [
        [56, 57, 58, 59, 60, 61, 62, 63],
        [48, 49, 50, 51, 52, 53, 54, 55],
        [40, 41, 42, 43, 44, 45, 46, 47],
        [32, 33, 34, 35, 36, 37, 38, 39],
        [24, 25, 26, 27, 28, 29, 30, 31],
        [16, 17, 18, 19, 20, 21, 22, 23],
        [8, 9, 10, 11, 12, 13, 14, 15],
        [0, 1, 2, 3, 4, 5, 6, 7]
    ]


# 当前对局的时间进程 开局、中局、残局
class GameCourse:
    OPEN_GAME = "OG"
    MIDDLE_GAME = "MG"
    END_GAME = "EG"

    # 开局时兵和轻子的阈值
    OPEN_PAWN_THRESHOLD = 7
    OPEN_PAWN_LIGHT_THRESHOLD = 3

    # 残局的阈值
    END_LIGHT_THRESHOLD = 2
    END_ROOK_THRESHOLD = 2


# 颜色枚举 和chess库保持一致
class Color:
    WHITE = True
    BLACK = False


# 棋子对应的得分
class Score:
    SCORE_LIST = {
        # 开局中局残局
        'OG': {
            'P': 100,
            'B': 350,
            'N': 325,
            'R': 500,
            'Q': 900,
            'p': -100,
            'b': -350,
            'n': -325,
            'r': -500,
            'q': -900,
            'k': 0,
            'K': 0,
            '.': 0,
        },
        'MG': {
            'P': 100,
            'B': 350,
            'N': 325,
            'R': 500,
            'Q': 900,
            'p': -100,
            'b': -350,
            'n': -325,
            'r': -500,
            'q': -900,
            'k': 0,
            'K': 0,
            '.': 0,
        },
        'EG': {
            'P': 100,
            'B': 350,
            'N': 325,
            'R': 500,
            'Q': 900,
            'p': -100,
            'b': -350,
            'n': -325,
            'r': -500,
            'q': -900,
            'k': 0,
            'K': 0,
            '.': 0,
        },
    }


# 叠兵问题 开局和残局影响较小 中局最大
class PawnPiled:
    SET = {
        'OG': {
            'attacked': -50,
            'normal': -20,
            'attack_and_protected': -25,
            # 开局被保护的叠兵扣减的少
            'protected': -20
        },
        'MG': {
            'attacked': -70,
            'normal': -35,
            'attack_and_protected': -35,
            'protected': -15
        },
        'EG': {
            'attacked': -50,
            'normal': -20,
            'attack_and_protected': -25,
            'protected': -15
        },
    }


# 不能王车易位出来的车
class BadCastleRook:
    SET = {
        # 这边计算的少一点 因为到时候计算每个棋子控制的格点还要再次计算
        'OG': {
            'narrow': -300,
            'middle': -100,
            'wide': -50
        },
        'MG': {
            'narrow': -200,
            'middle': -100,
            'wide': 0
        },
        'EG': {
            'narrow': -200,
            'middle': -20,
            'wide': 0,
        },
    }
    # 车能控制的格点数
    threshold = {
        'narrow': 3,
        'wide': 7,
    }


# 棋子控制的格点得分奖励 可以忽略掉兵
class PieceControlBonus:
    SET = {
        'OG': {
            'knight': {
                'narrow': 20,
                'middle': 50,
                'wide': 100,
            },
            'bishop': {
                'narrow': 20,
                'middle': 70,
                'wide': 150,
            },
            'rook': {
                'narrow': 0,
                'middle': 50,
                'wide': 100,
            },
            'queen': {
                'narrow': 0,
                'middle': 20,
                'wide': 30,
            },
        },
        'MG': {
            'knight': {
                'narrow': 30,
                'middle': 60,
                'wide': 120,
            },
            'bishop': {
                'narrow': 30,
                'middle': 70,
                'wide': 180,
            },
            'rook': {
                'narrow': 0,
                'middle': 80,
                'wide': 150,
            },
            'queen': {
                'narrow': 0,
                'middle': 40,
                'wide': 60,
            },
        },
        'EG': {
            'knight': {
                'narrow': 10,
                'middle': 80,
                'wide': 150,
            },
            'bishop': {
                'narrow': 40,
                'middle': 80,
                'wide': 200,
            },
            'rook': {
                'narrow': 0,
                'middle': 70,
                'wide': 160,
            },
            'queen': {
                'narrow': 0,
                'middle': 80,
                'wide': 200,
            },
        },
    }
    # 各种棋子控制格点的多少
    threshold = {
        'knight': {
            'narrow': 2,
            'wide': 5
        },
        'bishop': {
            'narrow': 4,
            'wide': 10,
        },
        'queen': {
            'narrow': 6,
            'wide': 15,
        },
        'rook': {
            'narrow': 4,
            'wide': 10,
        }
    }


# 将要升变的通路兵 距离底线距离不同得分不同
class PawnWillPromotion:
    SET = {
        'OG': {
            6: 100,
            5: 120,
            4: 130,
            3: 150,
            2: 200,
            1: 300,
        },
        'MG': {
            6: 120,
            5: 150,
            4: 200,
            3: 250,
            2: 300,
            1: 400,
        },
        'EG': {
            6: 200,
            5: 300,
            4: 400,
            3: 500,
            2: 600,
            1: 800,
        },
    }
    # 如果这个兵不受保护 那就乘以这个值
    WEAK_LOSS = 0.2


class Result:
    WHITE_WIN = '1-0'
    BLACK_WIN = '0-1'
    DRAW = '1/2-1/2'
    NOT_STOP = '*'


# 先锋的估值 只包括轻子和兵
class Outpost:
    SET = {
        'OG':{
            'p':{
                # 距离底线的距离
                5:-20,
                4:-25,
                3:-30,
                2:-35,
            },
            'P': {
                # 距离底线的距离
                5: 20,
                4: 25,
                3: 30,
                2: 35,
            },
            'n':{
                5:-50,
                4:-70,
                3:-100,
                2:-180
            },
            'N':{
                5: 50,
                4: 70,
                3: 100,
                2: 180
            },
            'b':{
                5:-30,
                4:-40,
                3:-30,
                2:-30,
            },
            'B': {
                5: 30,
                4: 40,
                3: 30,
                2: 30,
            },
        },
        'MG':{
            'p': {
                # 距离底线的距离
                5: -40,
                4: -50,
                3: -60,
                2: -100,
            },
            'P': {
                # 距离底线的距离
                5: 40,
                4: 50,
                3: 60,
                2: 100,
            },
            'n': {
                5: -60,
                4: -80,
                3: -100,
                2: -180
            },
            'N': {
                5: 60,
                4: 80,
                3: 100,
                2: 180
            },
            'b': {
                5: -30,
                4: -40,
                3: -30,
                2: -30,
            },
            'B': {
                5: 30,
                4: 40,
                3: 30,
                2: 30,
            },
        },
        'EG':{
            'p': {
                # 距离底线的距离
                5: -20,
                4: -25,
                3: -30,
                2: -35,
            },
            'P': {
                # 距离底线的距离
                5: 20,
                4: 25,
                3: 30,
                2: 35,
            },
            'n': {
                5: -50,
                4: -55,
                3: -80,
                2: -100
            },
            'N': {
                5: 50,
                4: 55,
                3: 80,
                2: 100
            },
            'b': {
                5: -30,
                4: -40,
                3: -30,
                2: -30,
            },
            'B': {
                5: 30,
                4: 40,
                3: 30,
                2: 30,
            },
        }
    }